document.onkeydown = function (e) {//键盘按键控制
        e = e || window.event;
        if ((e.ctrlKey && e.keyCode == 82) || //ctrl+R
            e.keyCode == 116) {//F5刷新，禁止
            setTimeout(function () { window.location.reload(); }, 100);//延时提醒，要不alert会导致return false被alert挂起从而浏览器执行了刷新
            return false;
        }
    }
var jsonData={
  "deviceType": {
    "0": "GPRS设备",
    "1": "WIFI设备"
  },
  "deviceState": {
    "0": "故障",
    "1": "超限",
    "2": "在线",
    "3": "离线"
  },
  "sceneId":{
    "1": "常温库",
    "2": "阴凉库",
    "3": "冷藏库",
    "4": "冷藏车",
    "5": "冷藏箱",
    "6": "医用冰箱",
    "0": "其他"
  },
   "deviceStateColor": {
    "0": "<p style='color:#fad60d;'>故障</p>",
    "1": "<p style='color:red;'>超限</p>",
    "2": "<p style='color:#5ebdc7;'>在线</p>",
    "3": "<p style='color:#999;'>离线</p>"
  },
  "deviceState":{
  	"0":"正常",
  	"1":"维护中",
  	"2":"废弃"
  }
};





  /**
   ****************************jq扩展函数*******************************v**
   */
  /**
   * 全选
   */
  $(function() {
    $('.table-sort').on('click', '.btn-checkall', function() {
      $('.btn-checkall').prop('checked', this.checked);
      $('[type="checkbox"][name="sublist"]').prop("checked", this.checked);
    });
    $('.table-sort').on('click', '[type="checkbox"][name="sublist"]', function() {
      $('.btn-checkall').prop("checked", $('[type="checkbox"][name="sublist"]').length == $('[type="checkbox"][name="sublist"]:checked').length ? true : false);
    });
    /**
     * 提示
     */
    $('.tips-icon,.tips-obj').hover(function() {
      $(this).find('.dialog-warp').show();
      $(this).find('.dialog-warp').stop();
      $(this).find('.dialog-warp').animate({
        "opacity": 1
      }, 300);
    }, function() {
      $(this).find('.dialog-warp').stop();
      $(this).find('.dialog-warp').animate({
        "opacity": 0
      }, 300);
      $(this).find('.dialog-warp').hide();
    })
    $('.dialog-warp').each(function() {
      var H = $(this).height();
      $(this).css('margin-top', -H / 2);
    });
    /**
     * 速度动画
     * @param {Object} obj
     */
    var $obj = $('.fly-numberAdd');
    $obj.each(function() {
      var $this = $(this);
      var max_number = $this.data("value"); //最大值
      var plus_number = Math.ceil(max_number / 99); //增加值,因为时间变化一样的
      var start_number = 0;
      var Interval = setInterval(function() {
        start_number += plus_number;
        if(start_number > max_number) {
          $this.html(max_number);
          clearInterval(Interval);
        } else { 
          $this.text(start_number);
        }
      }, 10);
    });
    /**
     * 数字过万则处理
     */
    $('.fly-number').each(function(i, obj) {
      var n = +$(obj).data('number');
      if(n > 10000) {
        $(obj).text((n / 10000).toFixed(2) + '万');
      }
    });
    
  });


//table配置项汉化
var lang = {
  "sProcessing": "<div class='loader'>加载中...</div>",
  "sLengthMenu": "每页 _MENU_ 项",
  "sZeroRecords": "换个搜索词试试呢？暂无数据",
  "sInfo": "当前显示第 _START_ 至 _END_ 项，全部 _TOTAL_ 项。",
  "sInfoEmpty": "当前显示第 0 至 0 项，全部 0 项",
  "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
  "sInfoPostFix": "",
  "sSearch": "本地搜索：",
  "sUrl": "",
  "sEmptyTable": "暂无数据",
  "sLoadingRecords": "载入中...",
  "sInfoThousands": ",",
  "oPaginate": {
    "sFirst": "首页",
    "sPrevious": "上一页",
    "sNext": "下一页",
    "sLast": "最后页",
    "sJump": "跳转至"
  },
  "oAria": {
    "sSortAscending": ": 以升序排列此列",
    "sSortDescending": ": 以降序排列此列"
  }
};
//注册弹出方法
function layer_show(title, url, id, w, h) {
	
  if(title == null || title == '') {
    title = false;
  };
  if(w == null || w == '') {
    w = 800;
  };
  if(h == null || h == '') {
    h = ($(window).height() - 300);
  };
 /* layer.open({
    type: 2,
    area: [w + 'px', h + 'px'],
    fixed: false,
    offset: 't',
    maxmin: true,
    shade: false,
    title: title,
    content: url
  });*/
  //iframe层
	layer.open({
	  type: 2,
	  title: title,
	  offset: 't',
	  maxmin:false,
	  shadeClose: true,
	  shade: 0.5,
	  area: [w + 'px', h + 'px'],
	  content:  url //iframe的url
	}); 
	
	
};
/**
 * 关闭弹出框口
 */
function layer_close() {
  var index = parent.layer.getFrameIndex(window.name);
  parent.layer.close(index);
}
/**
 *********************************扩展原生函数**********************************
 */
/**
 * addclass函数封装
 * @param {Object} obj
 * @param {Object} classStr
 */
function addClass(obj, classStr) {
  var array = noRepeat(trim(obj.className).split('\s+'));
  if(!inArray(array, classStr)) {
    array.push(classStr);
  }
  obj.className = array.join(' ');
  return obj;
}
/**
 * removeclass函数封装
 * @param {Object} obj
 * @param {Object} classStr
 */
function removeClass(obj, classStr) {
  var array = noRepeat(trim(obj.className).split('\s+'));
  var index = indexOf(array, classStr);
  if(index != -1) {
    classStr.splice(index, 1);
    obj.className = classStr.join(' ');
  }
  return obj;
}
/**
 * toggleClass函数封装
 * @param {Object} obj
 * @param {Object} classStr
 */
function toggleClass(obj, classStr) {
  var array = noRepeat(trim(obj.className).split('\s+'));
  if(inArray(array, classStr)) {
    removeClass(obj, classStr);
  } else {
    addClass(obj, classStr);
  }
}

/**
 * 格式化时间戳
 */
function replaceTime(nS) {
//return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
  var dt = new Date(nS * 1000);
		var date = [
			[dt.getFullYear(), dt.getMonth() + 1, dt.getDate()].join('-'), [dt.getHours(), dt.getMinutes(), dt.getSeconds()].join(' : ')
		].join(' ').replace(/(?=\b\d\b)/g, '0');
		return date;
}
/**
 * 求数组最大值
 */
Array.prototype.max = function() {
  return Math.max.apply(null, this);
};
/**
 * 求数组最小值
 */
Array.prototype.min = function() {
  return Math.min.apply(null, this);
};
/**
 * 数组排序
 * @param {name} name
 * arr.sort(sortBy('name'))
 */
function sortBy(name) {
  return function(o, p) {
    var a, b;
    if(typeof o === "object" && typeof p === "object" && o && p) {
      a = o[name];
      b = p[name];
      if(a === b) {
        return 0;
      }
      if(typeof a === typeof b) {
        return a < b ? -1 : 1;
      }
      return typeof a < typeof b ? -1 : 1;
    } else {
      throw("error");
    }
  }
};
/**
 * 时间差
 * @param {Object} olddate
 */
function timeDiff(olddate) {
  var old = new Date(olddate);
  var dateNum = (new Date()) - old;
  var days = dateNum / 1000 / 60 / 60 / 24;
  return Math.floor(days);
}
/**
 * 获取当前时间
 */
function getNowDate() {
  var now = new Date();
  return now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate();
}

/**
 * 获取昨天的日期
 * @returns {string}
 */
function getYestoday() {
  var myDate=new Date();
  myDate.setDate(myDate.getDate()-1);
  return myDate.getFullYear() + "-" + (myDate.getMonth() + 1) + "-" + myDate.getDate();
}

/**
 * 获取一周前的日期
 * @returns {string}
 */
function getWeekBefor() {
  var myDate=new Date();
  myDate.setDate(myDate.getDate()-7);
  return myDate.getFullYear() + "-" + (myDate.getMonth() + 1) + "-" + myDate.getDate();
}

function getNowFormatDate() {
  var date = new Date();
  var seperator1 = "-";
  var seperator2 = ":";
  var month = date.getMonth() + 1;
  var strDate = date.getDate();
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
  }
  var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
      + " " + date.getHours() + seperator2 + date.getMinutes()
      + seperator2 + date.getSeconds();
  return currentdate;
}
/**
 * 获取星期几
 */
function getWeek() {
  return(new Date()).getDay();
}
getWeek();
/**
 * 数组的indexOf方法封装
 * @param {Object} arr
 * @param {Object} value
 * @param {Object} start
 */
function indexOf(arr, value, start) {
  //如果不设置start,则默认start为0
  if(arguments.length == 2) {
    start = 0;
  }
  //如果数组中存在indexOf方法，则用原生的indexOf方法
  if(arr.indexOf) {
    return arr.indexOf(value, start);
  }
  for(var i = 0; i < arr.length; i++) {
    if(arr[i] === value) {
      return i;
    }
  }
  return -1;
}
/**
 * 数组去重方法封装
 * @param {Object} arr
 */
function noRepeat(arr) {
  var result = [];
  for(var i = 0; i < arr.length; i++) {
    if(indexOf(result, arr[i]) == -1) {
      result.push(arr[i]);
    }
  }
  return result;
}
/**
 * inArray方法封装
 * @param {Object} arr
 * @param {Object} value
 */
function inArray(arr, value) {
  for(var i = 0; i < arr.length; i++) {
    if(arr[i] === value) {
      return true;
    }
  }
  return false;
}
/**
 * 去除首尾空格函数封装
 * @param {Object} arr
 */
function trim(arr) {
  var result = arr.replace(/^\s+|\s+$/g, '');
  return result;
}

 //表单数据站环卫
function formToJson(formObj){
	   var o={};
	   var a=formObj.serializeArray();
	   $.each(a, function() {
	       if(this.value){
	           if (o[this.name]) {
	               if (!o[this.name].push) {
	                   o[this.name]=[ o[this.name] ];
	               }
	                   o[this.name].push(this.value || null);
	           }else {
	               if($("[name='"+this.name+"']:checkbox",formObj).length){
	                   o[this.name]=[this.value];
	               }else{
	                   o[this.name]=this.value || null;
	               }
	           }
	       }
	   });
	   return JSON.stringify(o);
};

//存储 登录ID 跟accessToken
var storage=window.localStorage;
adminId = storage.getItem("adminId");
var accessToken = storage.getItem("accessToken");




//url传参方式
userId = getQueryString("userId",window.location.href); //用户传ID
deviceInspectionId = getQueryString("deviceInspectionId",window.location.href);
deviceId = getQueryString("deviceId",window.location.href); //设备传ID
teamId = getQueryString("teamId",window.location.href); //
function getQueryString(name, url) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    if (!url || url == ""){
	    url = window.location.search;
    }else{
    	url = url.substring(url.indexOf("?"));
    }
    r = url.substr(1).match(reg)
    if (r != null) return unescape(r[2]); return null;
}
//ajax的url
var url = 'http://60.205.229.131:8085/mark';
//AJAX 的请求成功判断条件
function ifajax(data){
	debugger;
	
	window.parent.location.href = 'login.html';
}


/**
 * 根据配置项名称和key获取json文件中的配置项value
 * @param optionName
 * @param optionKey
 * @returns {*}
 */
function getOption(optionName, optionKey) {
    if (optionName!=undefined && optionKey!=undefined) {
        var optionValue="";
        $.getJSON("json/options.json", function (data) {
            option = data[optionName];
            if (option)
              optionValue=option[optionKey];
        });
        return optionValue;
    }else
        return "";
}

/**
 * 根据配置项名称和key获取json文件中的配置项value
 * @param optionName
 * @param optionKey
 * @returns {*}
 */
function getOption(optionName, optionKey) {
    if (optionName!=undefined && optionKey!=undefined) {
        var optionValue="";
        //$.getJSON("json/options.json", function (data) {
            option = jsonData[optionName];
            if (option)
              optionValue=option[optionKey];
        //});
        return optionValue;
    }else
        return "";
}
// 验证手机号，input--onchange="checkMobile()"
function checkMobile(){ 
    var sMobile = document.getElementById('userPhone').value;
    if(!(/^1[3|5][0-9]\d{4,8}$/.test(sMobile))){ 
        layer.msg('请输入正确的手机号');
        return false; 
    } 
} 
function much(){
	var r = document.getElementById('step').value;
	if(!(/^([1-9]|[1-5][0-9]|60)$/.test(r))){
		layer.msg('上传间隔1-60之间');
		$("#step").val("");
    return false; 
	}
}

function muchs(){
	var r = document.getElementById('alarmStep').value;
	if(!(/^([1-9]|[1-5][0-9]|60)$/.test(r))){
		layer.msg('报警间隔1-60之间');
		$("#alarmStep").val("");
    return false; 
	}
}

